package day12.reflect;

import java.lang.reflect.InvocationTargetException;
import java.util.Date;
import java.util.Scanner;

public class Test2 {
    public static void main(String[] args) throws ClassNotFoundException {
        System.out.println("输入类名:");
        String s = new Scanner(System.in).nextLine();
        Class<?> c = Class.forName(s);
        try {
            Object o1 = c.getDeclaredConstructor().newInstance();
            System.out.println(o1);
        } catch (Exception e) {
            System.out.println("无法执行无参构造");
        }
        try {
            Object o2 = c.getConstructor(int.class).newInstance(5);
            System.out.println(o2);
        } catch (Exception e) {
            System.out.println("无法执行int参数构造");
        }


    }
}
